SpringBoot 集成Flowable设计器(Flowable

您所在的位置:网站首页 flowable modelservice SpringBoot 集成Flowable设计器(Flowable

SpringBoot 集成Flowable设计器(Flowable

2024-07-16 16:29:49| 来源: 网络整理| 查看: 265

目录

一、项目场景:

提示:使用版本6.7.0

公司使用前后端项目分离,前端使用bpmn插件生成bpmn xml文件,后端解析处理数据。今天主要介绍后端集成flowable设计器的过程中遇到的问题。 如需了解flowable框架集成请参考文档 Flowable BPMN 用户手册 (v 6.3.0)

二、集成过程

提示:项目中遇到的问题: 为什么需要自己集成Flowable设计器?因为SpringBoot提供的依赖只集成Flowable引擎模块,没有集成modeler模块。SpringBoot集成Flowable需要导入如下依赖:

org.flowable flowable-spring-boot-starter-process ${flowable.version}

可以看到没有集成和modeler相关的依赖,如下是flowable源码中提供的流程设计器模块: flowable-ui-modeler-conf: 放置一些列的配置项 flowable-ui-modeler-frontend: 前端 flowable-ui-modeler-logic: 放置Service以及dao层 flowable-ui-modeler-rest: 放置Controller层 因为只需要集成flowable操作model 接口相关组件,所以只需要集成logic模块即可,添加依赖如下:

org.flowable flowable-ui-modeler-logic ${flowable.version} 三、问题总结:

提示:这里填写问题的分析:

1、程序启动报错(flowable.common.app.idm-url must be set)`Failed to instantiate [org.flowable.ui.common.service.idm.RemoteIdmService]: Factory method 'remoteIdmService' threw exception; nested exception is java.lang.IllegalArgumentException: `flowable.common.app.idm-url` must be set`

这个是由于flowable调用自己的用户权限导致的,如果把flowable集成自己的框架里面,就不需要用它自带的用户体现和权限了。 解决方案:将FlowableUiSecurityAutoConfiguration排除

@SpringBootApplication(exclude = {FlowableUiSecurityAutoConfiguration.class}) 2、引入modelService报红,运行报错Field modelService in com.nmb.zx.base.sys.flow.service.FlowModelInfoService required a bean of type 'org.flowable.ui.modeler.serviceapi.ModelService' that could not be found.

解决方案:参考flowable flowable-ui-modeler-conf组件中的源码中的配置类扫描我们需要的注入的类所在的包即可: 添加ModelerBeanConfig.java配置类到项目任意位置:

import org.flowable.ui.common.properties.FlowableCommonAppProperties; import org.flowable.ui.modeler.repository.ModelRepositoryImpl; import org.flowable.ui.modeler.service.FlowableModelQueryService; import org.flowable.ui.modeler.service.ModelImageService; import org.flowable.ui.modeler.service.ModelServiceImpl; import org.flowable.ui.modeler.serviceapi.ModelService; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.FilterType; /** * Greated by xiang on 2023/2/27 */ @Configuration @ComponentScan(value = { // "org.flowable.ui.modeler.conf", //不引入 conf "org.flowable.ui.modeler.repository", "org.flowable.ui.modeler.service", // "org.flowable.ui.modeler.security",//授权方面的都不需要 // "org.flowable.ui.common.conf", // flowable 开发环境内置的数据库连接 // "org.flowable.ui.common.filter",// IDM 方面的过滤器 // "org.flowable.ui.common.service", "org.flowable.ui.common.repository", // "org.flowable.ui.common.security",//授权方面的都不需要 // "org.flowable.ui.common.tenant" }, excludeFilters = { @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ModelRepositoryImpl.class)}) @EnableConfigurationProperties({FlowableCommonAppProperties.class}) public class ModelerBeanConfig { @Bean public ModelService createModelService() { return new ModelServiceImpl(); } @Bean public ModelImageService createModelImageService() { return new ModelImageService(); } @Bean public FlowableModelQueryService createFlowableModelQueryService() { return new FlowableModelQueryService(); } }

mybatisPlus中添加配置 添加BPMN配置文件FlowBpmnConfig

import com.fasterxml.jackson.databind.ObjectMapper; import com.nmb.zx.base.core.config.flow.customcache.CustomDeploymentCache; import com.nmb.zx.base.core.config.flow.customcache.CustomProcessDefinitionInfoCache; import org.apache.ibatis.session.SqlSessionFactory; import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.spring.SpringProcessEngineConfiguration; import org.flowable.spring.boot.EngineConfigurationConfigurer; import org.flowable.validation.ProcessValidatorFactory; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; /** * 功能描述: * 〈flowable配置〉 * @Author: 85122 * @Date: 2023/2/28 15:16 */ @Configuration public class FlowBpmnConfig implements EngineConfigurationConfigurer { @Autowired private CustomDeploymentCache customDeploymentCache; @Autowired private CustomProcessDefinitionInfoCache customProcessDefinitionInfoCache; @Override public void configure(SpringProcessEngineConfiguration configuration) { configuration.setEnableProcessDefinitionInfoCache(true); configuration.setProcessDefinitionCache(customDeploymentCache); configuration.setProcessDefinitionInfoCache(customProcessDefinitionInfoCache); //设置自定义的uuid生成策略 configuration.setIdGenerator(uuidGenerator()); } @Bean public ProcessValidatorFactory processValidator(){ return new ProcessValidatorFactory(); } @Bean public ObjectMapper objectMapper() { return new ObjectMapper(); } @Bean public UuidGenerator uuidGenerator() { return new UuidGenerator(); } /** * BpmnXMLConverter * * @return BpmnXMLConverter */ @Bean public BpmnXMLConverter createBpmnXMLConverter() { return new BpmnXMLConverter(); } /** * 在配置文件中如果没有字段,使用@Value的时候就会忽略掉,不会报错 * * @return */ @Bean public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setIgnoreUnresolvablePlaceholders(true); return configurer; } @Bean(destroyMethod = "clearCache") @Qualifier("flowableModeler") public SqlSessionTemplate modelerSqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { return new SqlSessionTemplate(sqlSessionFactory); } } import org.flowable.common.engine.impl.persistence.StrongUuidGenerator; /** * 功能描述: * 〈uuid生成规则〉 * @Author: 85122 * @Date: 2023/2/28 15:16 */ public class UuidGenerator extends StrongUuidGenerator { @Override public String getNextId() { String uuid = super.getNextId(); uuid = uuid.replaceAll("-", ""); return uuid; } } import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache; import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry; import org.flowable.engine.repository.ProcessDefinition; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; /** * Very simplistic cache implementation that only caches one process definition. * * @author Joram Barrez */ @Component public class CustomDeploymentCache implements DeploymentCache { protected String id; protected ProcessDefinitionCacheEntry entry; @Override public ProcessDefinitionCacheEntry get(String id) { if (id.equals(this.id)) { return entry; } return null; } @Override public void add(String id, ProcessDefinitionCacheEntry object) { this.id = id; this.entry = object; } @Override public void remove(String id) { if (id.equals(this.id)) { this.id = null; this.entry = null; } } @Override public void clear() { this.id = null; this.entry = null; } @Override public boolean contains(String id) { return id.equals(this.id); } @Override public Collection getAll() { if (entry != null) { return Collections.singletonList(entry); } else { return new ArrayList(); } } @Override public int size() { if (entry != null) { return 1; } else { return 0; } } // For testing purposes only public ProcessDefinition getCachedProcessDefinition() { if (entry == null) { return null; } return entry.getProcessDefinition(); } } import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache; import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionInfoCacheObject; import org.springframework.stereotype.Component; import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @Component public class CustomProcessDefinitionInfoCache implements DeploymentCache { private final Map cache = new ConcurrentHashMap(); @Override public ProcessDefinitionInfoCacheObject get(String id) { return cache.get(id); } @Override public boolean contains(String id) { return cache.containsKey(id); } @Override public void add(String id, ProcessDefinitionInfoCacheObject object) { cache.put(id, object); } @Override public void remove(String id) { cache.remove(id); } @Override public void clear() { cache.clear(); } @Override public Collection getAll() { return cache.values(); } @Override public int size(){ return cache.size(); } } 3、启动后访问接口直接重定向到登录页面

import org.flowable.ui.common.security.SecurityConstants; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; /** * 说明:重构ModelerSecurity 绕过登录 */ @Configuration(proxyBeanMethods = false) @EnableWebSecurity public class ModelerSecurityConfiguration { @Configuration @Order(SecurityConstants.MODELER_API_SECURITY_ORDER) public static class ModelerApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setTargetUrlParameter("redirectTo"); http.headers().frameOptions().disable(); http.csrf().disable().authorizeRequests().antMatchers("/**/**").permitAll().anyRequest().authenticated().and().httpBasic(); } } } 4、运行成功请求接口

找不到act_de_model表,因为flowable将act_re_model改成了act_de_model表了,所以需要手动添加配置类生产act_de_model表:

import liquibase.Liquibase; import liquibase.database.Database; import liquibase.database.DatabaseConnection; import liquibase.database.DatabaseFactory; import liquibase.database.jvm.JdbcConnection; import liquibase.exception.DatabaseException; import liquibase.resource.ClassLoaderResourceAccessor; import org.flowable.ui.common.service.exception.InternalServerErrorException; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.sql.DataSource; /** * 功能描述: * 〈生成ACT_DE_开头的数据表〉 * @Param: * @param null * @Return: * @Author: 85122 * @Date: 2023/2/28 15:00 */ @Configuration public class DatabaseConfiguration { private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DatabaseConfiguration.class); protected static final String LIQUIBASE_CHANGELOG_PREFIX = "ACT_DE_"; @Bean public Liquibase liquibase(DataSource dataSource) { LOGGER.info("Configuring Liquibase"); Liquibase liquibase = null; try { DatabaseConnection connection = new JdbcConnection(dataSource.getConnection()); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection); database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogTableName()); database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX + database.getDatabaseChangeLogLockTableName()); liquibase = new Liquibase("META-INF/liquibase/flowable-modeler-app-db-changelog.xml", new ClassLoaderResourceAccessor(), database); liquibase.update("flowable"); return liquibase; } catch (Exception e) { throw new InternalServerErrorException("Error creating liquibase database", e); } finally { closeDatabase(liquibase); } } private void closeDatabase(Liquibase liquibase) { if (liquibase != null) { Database database = liquibase.getDatabase(); if (database != null) { try { database.close(); } catch (DatabaseException e) { LOGGER.warn("Error closing database", e); } } } } }


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭